package com.zcr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcr.pojo.Sellrecords;
import com.zcr.service.SellrecordsService;
import com.zcr.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @author： 张诚
 * @date： 2021-03-27 09:04
 */
@Controller
@RequestMapping("jilu")
public class SellrecordsController {

    @Resource
    private SellrecordsService sellrecordsService;

    @GetMapping("index")
    public String index(){
        return "xiaoshoujilu";
    }


    @ResponseBody()
    @GetMapping("/pagexinxi")
    public Result getbyjinhuojiru(String drugname, int page, int limit){
        Page<Sellrecords> list = sellrecordsService.getbyjinhuoxinxi(drugname, page, limit);
        Result result = new Result();
        result.setData(list.getRecords());
        result.setCount(Integer.parseInt(Long.toString(list.getTotal())));
        return result;
    }

    @ResponseBody()
    @PostMapping("/delete")
    public Result deleteAllDruginfos(@RequestBody String[] ids){
        for (int i=0;i<ids.length;i++){
            System.out.println(ids[i]);
        }
        try {
            sellrecordsService.deleteAllDruginfo(ids);
            return Result.success("删除公告成功");
        }catch (Exception ex){
            return Result.fail("删除药品失败",ex);
        }
    }

}
